package com.sky.controller;

import com.sky.constant.MessageConstant;
import com.sky.dto.common.PageRequest;
import com.sky.dto.common.ParamsID;
import com.sky.dto.common.QueryParams;
import com.sky.entity.CompetionCategory;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CompetitionCategoryService;
import com.sky.service.impl.CompetionCategoryServiceImpl;
import com.sky.vo.CompetionCategoryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/competition/category")
@Slf4j
@Validated
public class CompetitionCategoryController {
    @Autowired
    private CompetitionCategoryService competitionCategoryService;

    /**
     * 分页获取所有比赛分类列表
     */
     @PostMapping("/list")
    public Result<PageResult> getAllCompetitionCategoryList(@RequestBody PageRequest<QueryParams> queryParams) {
        log.info("获取所有比赛分类列表{}",queryParams);
        PageResult competitionCategories = competitionCategoryService.getAllCompetitionCategoryList(queryParams);
        return Result.success(competitionCategories, MessageConstant.OK_MESSAGE);
    }
    /**
     * 获取所有的竞赛分类
     */
    @PostMapping("/all")
    public Result<List<CompetionCategory>> getAllCompetitionCategory(@RequestBody QueryParams queryParams) {
        log.info("获取所有的竞赛分类: {}", queryParams);
        List<CompetionCategory> competionCategoryList = competitionCategoryService.getAllCompetitionCategory(queryParams);
        return Result.success(competionCategoryList, MessageConstant.OK_MESSAGE);

    }
    /**
     * 增加竞赛分类
     */
     @PostMapping("/add")
    public Result<String> addCompetitionCategory(@RequestBody CompetionCategoryVO competionCategoryVO) {
         log.info("增加竞赛分类: {}", competionCategoryVO);
         competitionCategoryService.addCompetitionCategory(competionCategoryVO);
         return Result.success(null, MessageConstant.OK_MESSAGE);
     }
    /**
     * 批量删除竞赛分类数据
     */
    @PostMapping("/delete")
    public Result<String> deleteCompetitionCategory(@RequestBody ParamsID paramsID) {
        log.info("批量删除竞赛分类数据: {}", paramsID);
        competitionCategoryService.deleteCompetitionCategory(paramsID);
        return Result.success(null, MessageConstant.OK_MESSAGE);
    }
    /**
     * 获取任务详情
     */
    @PostMapping("/detail")
    public Result<CompetionCategoryVO> getCompetitionCategoryDetail(@RequestBody Map<String, String> map) {
        log.info("获取竞赛分类详情: {}", map.get("id"));
        CompetionCategoryVO competionCategoryVO = competitionCategoryService.getCompetitionCategoryDetail(map.get("id"));
        return Result.success(competionCategoryVO, MessageConstant.OK_MESSAGE);
    }
    /**
     * 更新竞赛分类
     */
    @PostMapping("/update")
    public Result<String> updateCompetitionCategory(@RequestBody CompetionCategoryVO competionCategoryVO) {
        log.info("更新竞赛分类: {}", competionCategoryVO);
        competitionCategoryService.updateCompetitionCategory(competionCategoryVO);
        return Result.success(null, MessageConstant.OK_MESSAGE);
    }

}
